package com.jgzx.controller;


import com.jgzx.domain.vo.BlogUpdateVO;
import com.jgzx.domain.vo.BlogVO;
import com.jgzx.domain.vo.BlogaddVO;
import com.jgzx.domain.vo.BlogdeleteVO;
import com.jgzx.security.annotation.ReSubmit;
import com.jgzx.service.BlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "个人博客")
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Autowired
    private BlogService blogService;

    @ApiOperation("博客用户列表")
    @PostMapping("/select")
    public List<BlogVO> select(){
        //运行成功
        return blogService.select();
    }

    @ApiOperation("根据id查询博客")
    @PostMapping("/getinfo")
    public BlogVO getInfo(@Valid @RequestBody int id){
        //运行成功
        return blogService.getInfo(id);
    }

    @ApiOperation("根据id删除博客")
    @PostMapping("/delete")
    @ReSubmit
    //运行成功
    public BlogdeleteVO delete(@Valid @RequestBody int id){
        //获取删除的博客id
        return blogService.delete(id);
    }

    @ApiOperation("添加博客")
    @ReSubmit
    @PostMapping("/add")
    public BlogaddVO add(@Valid @RequestBody BlogVO blogVO){
        //返回新增的信息
        return blogService.Add(blogVO);
    }

    @ApiOperation("更新博客")
    @PostMapping("/updata")
    @ReSubmit
    public BlogUpdateVO updata(@Valid @RequestBody int id, String title, String anthor, int views){
        return blogService.updata(id, title, anthor, views);
    }
}
